import java.util.Scanner;
import java.util.Random;

public class ShooterMain {
public static void main(String[] args){
	//System.out.println("You are walking through the dusty streets of a small town in northern Oklahoma. \n A masked, armed, and shady figure stumbles his way out of the nearest saloon. \nFoolishly he insults your mother. Expecting a duel, you pull out your impenetrable riot sheild")
	int playerHealth = 3;
	int cpuHealth = 3;
	int playerChamber = 0;
	int cpuChamber = 0;
	int turnCount = 0;//DUDUDUDUDUDUDUDUDU!!! -Bryce
	int blockCount = 0;
	Scanner scan = new Scanner(System.in);
	Scanner blockk = new Scanner(System.in);
	Random rand = new Random();
	while(playerHealth > 0 && cpuHealth > 0){
		System.out.println("Type 1 for Block \nType 2 for Reload \nType 3 for Shoot");
		int input = scan.nextInt();
		
		turnCount++;
		boolean playerBlock = false;
		boolean cpuBlock = false;
		boolean playerShoot = false;
		boolean cpuShoot = false;		
		int cpuSelection = rand.nextInt(3);
		if(turnCount == 1){
			cpuSelection = 1;
		}
		if(playerChamber == 0 && cpuChamber != 0){
			if(cpuSelection == 0){
				cpuSelection = rand.nextInt(2) + 1;
			}
		}
		if(cpuChamber == 0 && cpuSelection == 2){
			cpuSelection = rand.nextInt(1);
		}
		if(cpuChamber == 3 && cpuSelection == 1){
			cpuSelection = rand.nextInt(1);
			if(cpuSelection == 1){
				cpuSelection = 2;
			}
			
		}
	
		while(blockCount == 4 && input == 1){
			System.out.println("You cannot block this turn! \n Type 2 for Reload \n Type 3 for Shoot");
			int blockscan = blockk.nextInt();
			if(blockscan != 1){
				blockCount = 0;
				input = blockscan;
			}
						
		}
			
			
			
		
		if(input == 1){
			playerBlock = true;
			blockCount++;
			System.out.println("You have blocked");
		}
		else if(input == 2){
			playerChamber++;
			System.out.println("You have reloaded. Your chamber is now at " + playerChamber);
			blockCount = 0; 
		}
		else if(input == 3){
			if(playerChamber == 0){
				System.out.println("You have shot. Your chamber was empty! nothing happened. ");
				blockCount = 0; 
			}
			else{
				playerChamber--;
				playerShoot = true;
				System.out.println("You have shot. Your chamber is now at " + playerChamber);
				blockCount = 0; 
			}
	
		}
		if(cpuSelection == 0){
			cpuBlock = true;
			System.out.println("The computer has blocked");
		}
		if(cpuSelection == 1){
			cpuChamber++;
			System.out.println("The computer has reloaded. His chamber is now at " + cpuChamber);
		}
		if(cpuSelection == 2){
			cpuChamber--;
			cpuShoot = true;
			System.out.println("The computer has shot. His chamber is now at " + cpuChamber);
		}
		
	
	if(playerShoot == true && cpuBlock == false){
		cpuHealth--;
		System.out.println("The computer has been shot! Computer health at " + cpuHealth);
	}
	if(cpuShoot == true && playerBlock == false){
		playerHealth--;
		System.out.println("You have been shot! your health is at " + playerHealth);
	}
	
	
	if(playerShoot == true && cpuBlock == true){	
			System.out.println("The computer blocked your shot!");
	}
	if(cpuShoot == true && playerBlock == true){	
			System.out.println("You blocked the computer's shot!");
			
}
}
	if(cpuHealth == 0 && playerHealth != 0){
		System.out.println("YOU WIN!");
	}
	if(playerHealth == 0 && cpuHealth != 0){
		System.out.println("YOU LOSE! :(");
	}
	if(cpuHealth == 0 && playerHealth == 0){
		System.out.println("IT'S A TIE!");
	}
}
}
